<?php

namespace app\api\model\music;

use app\logic\model\music\MusicLogicModel;
use app\logic\model\music\MusicWelfareLogicModel;
use app\logic\model\user\UserLogicModel;
use app\logic\single\GoodsSingle;
use app\logic\single\MusicSingle;

class MusicWelfareApiModel extends MusicWelfareLogicModel
{


    public function getApiList(array $param, array $where=[], string $field='*', $page=1, $limit=15,string $order='sort desc')
    {
        $query=$this->where($where)
            ->where(function ($q) use ($param){
                if(check_request($param,'status')){
                    $q->where("status",$param['status']);
                }
                if(check_request($param,'now')){
                    $q->where("start_time",'<',date('Y-m-d H:i:s'));
                    $q->where("end_time",'>',date('Y-m-d H:i:s'));
                }else{
                    if(check_request($param,'pre')){
                        $q->whereTime("end_time",'<',date('Y-m-d H:i:s'));
                    }
                }

            });
        $list = $query->field($field)->order($order)
            ->page($page,$limit)->select();
        $count = $query->count();
        if($count>0){
            $list = GoodsSingle::getInstance()->getGoodsList($list->toArray());
           unset($val);
        }
        return [$list,$count];
    }

    public function details($id, string $field='*')
    {
        $info = $this->getFindById($id,$field);
        if(empty($info)){
            return false;
        }
        $info['goods'] = GoodsSingle::getInstance()->getGoods($info['goods_id'],$info['type']);
        return $info;
    }

}